//
//  HUserInfoView.m
//  HTanzhi
//
//  Created by 陈贵 on 15/11/13.
//  Copyright © 2015年 hzj. All rights reserved.
//

#import "HUserInfoView.h"
#import "Masonry.h"
#import "HZJButton.h"

@interface HUserInfoView ()
//头像
@property (strong, nonatomic)  UIButton *iconB;

//介绍文本
@property (nonatomic ,strong)  UILabel *introL;

//注册按钮
@property (nonatomic ,strong) UIButton *registerB;

//登陆按钮
@property (nonatomic ,strong) UIButton *enterB;

//红色分割线
@property (nonatomic ,strong) UIView *lineV;

//底部灰色部分
@property (nonatomic ,strong) UIView *bottomV;

//头像中心据左边距离
//@property (nonatomic ,assign) CGFloat distanceLeft;

@end
@implementation HUserInfoView

- (instancetype )init{
    if (self = [super init]) {
        //------
        _iconB = [self addBthWithImage:@"iconNotLogin" andTitle:nil andAction:nil];
        //------
        _introL = [[UILabel alloc]init];
        _introL.text = @"hahaha";
        [self addSubview:_introL];
        //------
        _registerB = [self addBthWithImage:nil andTitle:@"注册" andAction:@selector(cilckTheRegisterB)];
        //------
        _enterB = [self addBthWithImage:nil andTitle:@"登陆" andAction:@selector(cilckTheEnterB)];
        //-----
        _lineV = [[UIView alloc]init];
        _lineV.backgroundColor = [UIColor redColor];
        [self addSubview:_lineV];
        //----
        _bottomV = [[UIView alloc]init];
        _bottomV.backgroundColor = [UIColor grayColor];
        [self addSubview:_bottomV];
    }
    return self;
}


- (CGFloat)heightWithIsEnter:(BOOL)isEnter{
    
    CGFloat w = [UIScreen mainScreen].bounds.size.width;
    CGFloat h = [UIScreen mainScreen].bounds.size.height;
    
    if (isEnter) {
        self.distanceLeft = 70;

    }else{
        self.distanceLeft = w * 0.5;
    }
    _enterB.hidden = isEnter;
    _registerB.hidden = isEnter;
    _lineV.hidden = isEnter;
    
    //两按钮的高度
    CGFloat Bh = 40 ;
    _iconB.bounds = CGRectMake( 0, 0, 80, 80);
    _iconB.center = CGPointMake( self.distanceLeft, h  * 0.1);
    //------
    [_introL sizeToFit];
    _introL.center = CGPointMake(_iconB.center.x, CGRectGetMaxY(_iconB.frame) + _introL.frame.size.height * 0.5 + 10);
    //------
    _registerB.frame = CGRectMake(0, CGRectGetMaxY(_introL.frame), w * 0.5, Bh);
    //------
    _enterB.frame = CGRectMake(w * 0.5, CGRectGetMaxY(_introL.frame), w * 0.5, Bh);
    //-----
    _lineV.bounds = CGRectMake(0, 0, 1, Bh * 0.6);
    _lineV.center = CGPointMake( w * 0.5, _registerB.frame.origin.y + Bh * 0.5);
    //-----
    _bottomV.frame = CGRectMake(0, CGRectGetMaxY(_registerB.frame), w, 20);
    
    
    NSLog(@"%lf",CGRectGetMaxY(_bottomV.frame));
    return CGRectGetMaxY(_bottomV.frame);

}

///生成按钮
- (UIButton *) addBthWithImage:(NSString *)iconName andTitle:(NSString *)title andAction:(SEL)action{
    
    HZJButton *bth = [HZJButton buttonWithType:UIButtonTypeCustom];

    if (iconName) {
        UIImage *imageB = [UIImage imageNamed:iconName];
        if (!imageB) {
            NSLog(@"请确认图片名");
        }
        NSLog(@"yongle");
        bth.hasHighLight = NO;
        [bth setImage:imageB forState:UIControlStateNormal];
    }
    
    [bth setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [bth addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [bth setTitle:title forState:UIControlStateNormal];
    
    [self addSubview:bth];
    return bth;
}
- (void) cilckTheRegisterB {
    _distanceLeft = [UIScreen mainScreen].bounds.size.width * 0.5;
    NSLog(@"%f",self.distanceLeft);
    NSLog(@"11111");

}
- (void) cilckTheEnterB {
    _distanceLeft = 50;
    [self layoutIfNeeded];

    UIView *v = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    v.backgroundColor = [UIColor whiteColor];
    
}
- (void)dealloc{
    NSLog(@"2");
}



@end
